﻿using BlueCrest.ConfigManagement.Storage.DB.ClassMaps.Flat;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;

namespace BlueCrest.ConfigManagement.Storage.DB.Service
{
    public interface INHibernateSessionFactory
    {
        ISessionFactory CreateSessionFactory();
    }


    public class NHibernateSessionFactory : INHibernateSessionFactory
    {
        public ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                    .Database(MsSqlConfiguration.MsSql2008.ConnectionString("Data Source=ALPHA\\SQLEXPRESS;Initial Catalog=ConfigDB;Integrated Security=SSPI;"))
                    .Mappings(m =>
                        m.FluentMappings.AddFromAssemblyOf<ScopeEntityMap>().Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()))

                    .BuildSessionFactory();
        }
    }

    
}
